package com.op.crm.webapp.action.security;

import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import com.op.crm.persist.model.Action;
import com.op.crm.util.DateUtil;
import com.op.crm.util.Utils;

public class ModifyActionFunction extends SecurityFactory<Action>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Action getModel() {
		if (actionParam == null)
			actionParam = new Action();
		return actionParam;
	}
	
	@Override
	public String execute() throws Exception {
		try {
			if (Utils.isBlank(actionParam.getActionId())) {
				setReturnValue("错误:动作编号为空!");
				return null;
			}
			if (Utils.isBlank(actionParam.getActionName())) {
				setReturnValue("错误:动作描述为空!");
				return null;
			}
			if (Utils.isBlank(actionParam.getAction())) {
				setReturnValue("错误:动作为空!");
				return null;
			}
			Action upAction = securityService.getAction(actionParam.getActionId());
			if (upAction == null) {
				setReturnValue("错误:此动作不存在!");
				return null;
			}
			
			upAction.setActionName(actionParam.getActionName());
			upAction.setAction(actionParam.getAction());
			upAction.setUpdateUser(getCurrentCRMUser().getUserId());
			upAction.setUpdateTime(DateUtil.formatStringByDate(new Date()));
			
			securityService.updateAction(upAction);
			
			setReturnValue("信息:修改动作成功!");
			upAction = null;
			actionParam = null;
			
		} catch (Exception e) {
			e.printStackTrace();
			setReturnValue("错误:系统异常，请联系管理员!");
			return null;
		}
		
		return null;
	}
}
